package com.beilang.hotline.telattach.manager.impl;

import com.beilang.base.util.DateUtil;
import com.beilang.base.util.StringUtil;
import com.beilang.hotline.telattach.dao.TelattachDAO;
import com.beilang.hotline.telattach.manager.TelattachMgr;
import com.beilang.hotline.telattach.model.TelattachModel;
import com.beilang.hotline.user.manager.UserMgr;
import com.beilang.hotline.user.model.UserModel;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class TelattachMgrImpl implements TelattachMgr {
    private TelattachDAO telattachDAO;
    private UserMgr userMgr;

    public void setUserMgr(UserMgr userMgr) {
        this.userMgr = userMgr;
    }

    public void setTelattachDAO(TelattachDAO telattachDAO) {
        this.telattachDAO = telattachDAO;
    }

    public TelattachModel createTelattachModel(TelattachModel telattachModel) {
        return telattachDAO.createTelattachModel(telattachModel);
    }

    public TelattachModel saveTelattachModel(TelattachModel telattachModel) {
        return telattachDAO.saveTelattachModel(telattachModel);
    }

    public void deleteTelattach(Long attachId) {
        telattachDAO.deleteTelattachModel(attachId);
    }

    public TelattachModel getTelattach(Long attachId) {
        return telattachDAO.getTelattachModel(attachId);
    }

    public List searchRecordAttachList(Long entityId,String entityType)
   {
       List l = new ArrayList();
       List list =  telattachDAO.searchRecordAttachList(entityId,entityType);
       if (list!=null&&!list.isEmpty())
       {

            Iterator itor= list.iterator();
             while (itor.hasNext()) {
                    TelattachModel telattachModel = (TelattachModel) itor.next();
                    telattachModel=setTelattachModelDesc(telattachModel);
                    l.add(telattachModel);
             }
       }
       return l;
   }
  public TelattachModel setTelattachModelDesc(TelattachModel telattachModel) {
        if (telattachModel == null) {
            return null;
        }

         if (!StringUtil.isEmpty(telattachModel.getCreateId())) {
            UserModel userModel = userMgr.getUser(telattachModel.getCreateId());
            if (userModel != null) {
                telattachModel.setUploadorStr(userModel.getUserName());
            }
        }
      telattachModel.setUploadTimeStr(DateUtil.formatDateTime(telattachModel.getCreateTime()));

      return telattachModel; 
  }
    
}
